﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class DangNhapDAO
    {
        public static int DangNhap(string tenDangNhap, string matKhau)
        {
            int kq;
            SqlConnection cn = DataProvider.ConnectionData();
            string sql = "sp_DangNhap";
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@tenDangNhap",tenDangNhap);
            cmd.Parameters.Add("@matKhau", matKhau);
            cmd.Parameters.Add("@kq", SqlDbType.Int);
            cmd.Parameters["@kq"].Direction = ParameterDirection.Output;
            cmd.Parameters["@kq"].Value = 0;
            cmd.ExecuteNonQuery();
            kq = Int32.Parse(cmd.Parameters["@kq"].Value.ToString());
            cn.Close();
            return kq;
        }
        public static int ThayDoiMatKhau(string tenDangNhap,string matKhauCu,string matKhauMoi)
        {
            int flag;
            SqlConnection cn = DataProvider.ConnectionData();
            string sql = "sp_ThayDoiMatKhau";
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@tenDangNhap", tenDangNhap);
            cmd.Parameters.Add("@matKhauCu", matKhauCu);
            cmd.Parameters.Add("@matKhauMoi", matKhauMoi);
            cmd.Parameters.Add("@kq", SqlDbType.Int);
            cmd.Parameters["@kq"].Direction = ParameterDirection.Output;
            cmd.Parameters["@kq"].Value = 0;
            cmd.ExecuteNonQuery();
            flag = Int32.Parse(cmd.Parameters["@kq"].Value.ToString());
            cn.Close();
            return flag;
        }
    }
}
